package net.zjitc.controller;

import net.zjitc.pojo.Orders;
import net.zjitc.pojo.OrdersCondition;
import net.zjitc.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author admin
 * @Date 2019/4/9 8:15
 */
@Controller
@RequestMapping("/manage/orders")
public class OrdersController {
    @Autowired
    OrdersService ordersService;

    @RequestMapping("/findAll")
    public String finAll(Model model){
        List<Orders> list = ordersService.findAll();
        model.addAttribute("orders",list);
        return "/admin/orders/list.jsp";
    }

    @RequestMapping("/findOrderById")
    public String findOrderById(String id,Model model){
        Orders list = ordersService.findOrderById(id);
        list.getOrderItemList().get(0).getProducts();
        model.addAttribute("order",list);
        return "/admin/orders/view.jsp";
    }

    @RequestMapping("/searchByOrdersCondition")
    @ResponseBody
    public List<Orders> searchByOrdersCondition(OrdersCondition ordersCondition){
        List<Orders> ordersList = ordersService.searchByOrdersCondition(ordersCondition);
        return ordersList;
    }

}
